﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>订单12</title>
		<link rel="stylesheet" href="{$_W['siteroot']}addons/lexiangpingou/app/view/default/admin/ceshi/bootstrap.min.css" /> 
		<link rel="stylesheet" href="{$_W['siteroot']}addons/lexiangpingou/app/view/default/admin/ceshi/index.css" />
		<script type="text/javascript" src="{$_W['siteroot']}addons/lexiangpingou/app/view/default/admin/ceshi/jquery-3.1.1.min.js" ></script>
		<script type="text/javascript" src="{$_W['siteroot']}addons/lexiangpingou/app/view/default/admin/ceshi/bootstrap.min.js" ></script>
        <script type="text/javascript" src="{$_W['siteroot']}addons/lexiangpingou/app/resource/layer/layer.js" ></script>

		<script type="text/javascript">

	 $(function(){

     $('#mytab a:eq(0)').tab('show');
     $("#ddIDtext").focus();
	
	
	//公共调用取得uid
        function strLoc(){		
	    var locatstr=window.location.href;
	    var locs=locatstr.lastIndexOf("=")+1 ;
		var uidstring=locatstr.substr(locs,locatstr.length-locs);
		return uidstring;
		}
	
    function runData(data,n){
	            var temTable=$(".ddlist table");
				if(n==0){
				if($(".list-head div span").text()==""){
				layer.alert("页面已经清空！");
				return false;
				}
				$(".list-head div span").text("");
				$("#ddIDtext").val("").focus();
				$(".ajaxTr").remove();
				$("#tolNum").text("0");
				$("#checkboxajax")[0].checked="";
				$("#noteInfo").val("");//备注信息
				}else{
				$(".list-head div span").text("");
				$(".ajaxTr").remove();
				$("#tolNum").text("0");
				$("#checkboxajax")[0].checked="";
				$("#order_number").text(data.orderno);//订单号
				$("#Ptime").text(data.ptime);//下单时间
                $("#Consignee").text(data.addname);//收货人
				$("#Ttime").text(data.ttime);//送货时间
				$("#Distribution_type").text(data.dispatchtype);//配送类型
				$("#Payment_method").text(data.paytype);//支付类型
				$("#mobile").text(data.mobile);//手机号
                $("#Pmethod").text(data.status);//订单状态
				$("#userAdd").text(data.address);//订单状态
                $("#Preferential_amount").text(data.discount_fee);//优惠金额
				$("#list_amount").text(data.goodsprice);//订单金额
				$("#final_amount").text(data.pay_price);//实付金额
				$("#noteInfo").val(data.Remark);//备注信息
		         //存储ajax数据，以备打印使用。	     
			    sessionStorage.setItem("dataPrint",JSON.stringify(data));
                for(var i=0;i<data.params.length;i++){
				temTable.append("<tr class='ajaxTr'><td>"+data.params[i].goodsname+"</td><td>"+data.params[i].optionname+"</td><td>"+data.params[i].goodsprice+"</td><td>"+data.params[i].gnum+"</td><td>"+data.params[i].goodsprice*data.params[i].gnum+"</Td></tr>");
				var tolNs=eval($("#tolNum").text())+eval(data.params[i].goodsprice*data.params[i].gnum);
				$("#tolNum").text(tolNs);
				    }
				  } //endif
				return;
				}
			 	
	  
	function orderTo(Order_ID){
	   if($("#checkboxajax").get(0).checked==""){
	 var Auto_verification=0;}else{Auto_verification=1;}
       Order_ID=Order_ID.toString(); 
		if(Order_ID==""){layer.alert("订单号码不能为空！");return false;}
	
	    $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/serch');}",
             data:{"orderno":Order_ID,"Auto_verification":Auto_verification,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			    if(data.statustype==0){
                layer.msg(data.message);
				}else if(data.statustype==1){
             	if(data.message!=""){layer.msg(data.msg);}
				runData(data);   //执行写出ajax信息到页面
				$("#empty").click(function(){runData(data,0);}); 	 //清空按扭
	         }
				return;
			  }
         });
  
     }//end irderTo
     
     function Nuclear_printing(){                       //核销并打印
	 var Order_ID=$("#order_number").text();
	 if(Order_ID==""){
	                 layer.alert("清空后无法执行此项操作！");
					  return;
					  }else{
	 	 $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/check');}",
             data:{"orderno":Order_ID,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
		   	  layer.msg(data.message);
			 }
         });
		} //endif
	  }
	 
	 
	     function printer(){ 
		    try
            {
                var objfs=new ActiveXObject("Scripting.FileSystemObject");
                var objprinter = objfs.CreateTextFile("LPT1:", true);
            }catch(Error)
            {
                layer.alert("无法获取Active插件，或者LPT1端口未连接打印机。错误信息："+Error.Message);
                return;
            }
			var data = JSON.parse(sessionStorage.getItem("dataPrint"));
			objprinter.Writeline("<h3>送货清单</h3>");
            objprinter.Writeline("订单编号："+data.orderno);
			objprinter.Writeline("配送类型："+data.dispatchtype);
			objprinter.Writeline("送货时间："+data.ttime);
			objprinter.Writeline("支付方式："+data.paytype);
            objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("商品信息");
			objprinter.Writeline("———————————————————————————————");
			for(var i=0;i<data.params.length;i++){
			objprinter.Writeline(data.params[i].goodsname+"    "+"X"+gnum);
			}
            objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("订单金额："+data.goodsprice);
			objprinter.Writeline("优惠金额："+data.discount_fee);
			objprinter.Writeline("实付金额："+data.pay_price);
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("用户信息");
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("用户名："+data.addname);
			objprinter.Writeline("手机号："+data.mobile);
			objprinter.Writeline("地址："+data.address);
			objprinter.Writeline("———————————————————————————————");
			objprinter.Writeline("备注信息："+data.Remark);
				  
           }
	 
	       
	      function Only_printing(){  		  //单独打印
		  
		  printer();
		  var Order_ID=$("#order_number").text();
	      if(Order_ID==""){
	                 layer.alert("清空后无法执行此项操作！");
					  return;
					  }else{
	 	 $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/print');}",
             data:{"orderno":Order_ID,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
		   	  layer.msg(data.message);
			}
         });
		} //endif
	  }
	 
	 $("#hxdd").on('click',Nuclear_printing);
	 $("#dd").on('click',Only_printing);
	 $("#lqdd").on("click",function(){   //点击拉取定单信息
	 var orderid=$("#ddIDtext").val();
	 orderTo(orderid);
	 });
 	 
	 
        //按手机号码搜索相关的订单号，并选择输出到页面的订单搜索中

 	    $("#seekTel").click(function(){
			  var telNumber=$("#telNumber");
                  if(telNumber.val()==""){layer.alert('手机号码不能为空！');telNumber.focus();return false;}
			      //开始ajax
                  var telphone=telNumber.val().toString();
             $.ajax({
             type: "GET",
             url: "{php echo app_url('admin/list/list');}",
             data:{"mobile":telphone,"uid":strLoc()},
			 dataType: "json",
             success: function(data){
			    if(data.statustype==0){
				layer.alert("您输入的手机号码有误，或无相联订单号！");
				return false;
				}
				  var wVal=window.innerWidth;;
				  var hVal=window.innerHeight;
				  var hh=hVal/1.5;
				 //开始订单弹出层
				if(wVal>hVal){areaW="600px"}else{areaW="90%"}
				 layer.open({
                      type: 1,
                      area: [areaW,'65%'],
                      shade:0.7,
                      title:"查询手机号：【 "+telNumber.val()+" 】的订单数据", //不显示标题
                      content: $('.orderWinpop'), //捕获的元素
                      cancel: function(index){
				      layer.close(index);
					  telNumber.val("");
                   // layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', {time: 5000, icon:6});
                   },
				   success: function(layero, index){
				    for(var i=0;i<data.list.length;i++){
			         $(".orderWinpop table").append("<tr><td><input type='radio' name=orderRadio/></td><td>"+data.list[i].ptime+"</td><td>"+data.list[i].orderno+"</td></tr>");
			         }//end read data
			   
			        //点击后选择订单输出到页面‘订单查询’框中
				
					var rAdios=$(".orderWinpop table tr td input[type='radio']");
					for(var i=0;i<rAdios.length;i++){
					rAdios.eq(i).click(function(layero,index){
					$("#ddIDtext").val($(this).parent().next().next().text());	
					layer.msg("开始查询订单号 . . . . . .");
                    telNumber.val("");	
                    setTimeout(function(){
					layer.closeAll('page');
					$("#lqdd").click();
					},650);					
					 });
					};//end for
				
			   
				   }
                 }); 
                 }//success
               });
			 }); 
			 
			 
	//设置回车触发
	
	$("#ddIDtext").keydown(function(event){
	    if(event.keyCode==13){
		 $("#lqdd").click();
		}
	}); 
	
	$("#telNumber").keydown(function(event){
	     if(event.keyCode==13){
		 $("#seekTel").click();
		}
		
	}); 
		
     	//设置快捷键
	var key_number=0;
	$(document).keydown(function(event){
	    if(event.keyCode == '78'){   //n
		$('#ddIDtext').focus();
		return false;
	    }
	    if(event.keyCode == '77'){   //m
	      $('#telNumber').focus();
		  return false;
	    }
	    if(event.keyCode == '81'){     //q
	    	$("#lqdd").click();
			return false;
			
	       }
	    if(event.keyCode == '87'){    //w
	        $('#seekTel').click();
			return false;
	    }
	    if(event.keyCode == '88'){   //x
	        $('#empty').click();
			layer.msg('清空数据');
			return false;
	    }
	    if(event.keyCode == '118'){     //f7
	        $('#hxdd').click();
			return false;
	    }
	    if(event.keyCode == '119'){     //f8
 	        $('#dd').click();
			return false;
	    }
	}); 		
     
     });// jquery onload
	 
	 </script>

	</head>

	<body>
	
	<div class="container">
		
			<div class="col-sm-12">
				                    <label class="tishi">订单编号：n</label>
									<label class="tishi">输入手机号：m</label>
									<label class="tishi">查询订单信息：q</label>
									<label class="tishi">查询手机号：w</label>
									<label class="tishi" for="">清空：x</label>
									<label class="tishi" for="">核销并打印：F7</label>
									<label class="tishi" for="">单独打印：F8</label>
			</div>
				<div class="row">
					<div class="col-sm-8">
						<div class="row">
							<div class="form-group">
								<div class="col-sm-8">
								
									<ul id="mytab" class="nav nav-tabs">
									
										<li>
											<a id="ddNum" href="#xw2" data-toggle='tab'>订单编号</a>
										</li>
										
									</ul>
									
								</div>
								
								<div class="clearfix"></div>
								<div class="col-sm-6">
								<div class="tab-content">
										<div class="tab-pane active fade in" id="xw1">
											<input id="ddIDtext" type="text" class="form-control" id="exampleInputEmail1" placeholder="订单ID(20160606849551885396)">
										</div>
										
										
										
								</div>
								</div>
								<div class="col-sm-4">
									<input id="lqdd" type="button" class="form-control btn btn-default" value="查询订单信息">
								</div>
								<div class="col-sm-2">
									<input id="empty" type="button" class="form-control btn btn-default" value="清空">
								</div>
								
							</div>
				

<div class="clear"></div>
	
 <div class="list-head">
 
  <div class="filedName">
    <label>订单编号：</label>
  </div>
  <div class="fileValue"><span id="order_number"></span> </div>

  <div class="filedName">
    <label>下单时间：</label>
  </div>
  <div class="fileValue"> <span id="Ptime"></span> </div>

  <div class="filedName">
    <label>收货人：</label>
  </div>
  <div class="fileValue"> <span id="Consignee"></span> </div>

  <div class="filedName">
    <label>手机号码：</label>
  </div>
  <div class="fileValue"> <span id="mobile"></span> </div>


  <div class="filedName">
    <label>送货时间：</label>
  </div>
  
  <div class="fileValue"> <span id="Ttime"></span> </div>
  
  <div class="filedName">
    <label>订单状态：</label>
  </div>
  <div class="fileValue"> <span id="Pmethod"></span> </div>
  
  
  <div class="filedName">
    <label>配送类型：</label>
  </div>

  <div class="fileValue"> <span id="Distribution_type"></span> </div>
  
  
  <div class="filedName">
    <label>支付方式：</label>
  </div>
  <div class="fileValue"> <span id="Payment_method"></span> </div>

  <div class="filedName">
    <label>用户地址：</label>
  </div>
  <div class="fileValue"> <span id="userAdd"></span> </div>
  
  
  <div class="fileValue" style="display:none" alt="优惠金额"> <span id="Preferential_amount"></span> </div>
    <div class="fileValue" style="display:none" alt="订单金额"> <span id="list_amount"></span> </div>
	  <div class="fileValue" style="display:none" alt="实付金额"> <span id="final_amount"></span> </div>
   
</div><!--list-head-->

			</div>
						
		</div>
					<div class="col-sm-4" id="telDiv">
					<label data-toggle='tab'>输入手机号：</label><input type="text" id="telNumber" placeholder="例：13800001111"onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
                    <button type="button" class="btn btn-default btn-sm" id="seekTel" style="margin-left:15px;">查询手机号</button>	
    				  </div>
	    			</div>
      <div class="clear"></div>     
		
		<div class="ddlist">
		    <table class="table table-bordered" >
		    <thead>
			<tr>
		    	<td>品名</td>
		    	<td>规格</td>
				<td>单价</td>
		    	<td>数量</td>
		    	<td>小计</td>
		    </tr>
			</thead>
		   </table>
		</div>
		
		<div class="row">
			<div class="col-sm-2" style="float: right;">
				<label>价格合计：<span id="tolNum">0</span>&nbsp;元</label>
				
			</div>
		</div>
		<div style="height:20px;"></div>
		<h5>订单备注：</h5>
		<textarea id="noteInfo" placeholder="备注信息..."></textarea>		
		<div class="row" style="margin-top:50px">
			<div class="col-sm-6">
					 <input type="checkbox" id="checkboxajax"/> <label for="checkboxajax" class="text-danger">自动核销</label>
			</div>
			<div class="col-sm-3">
				<input type="submit" id="hxdd" class="form-control btn btn-success" value="核销并打印">
			</div>
			<div class="col-sm-3">
				<input type="submit" id="dd" class="form-control btn btn-primary" value="单独打印">
			</div>
		</div>
		
	</div>
    
	<!--弹出层部份-->

		<div class="orderWinpop">
		    <table class="table table-bordered" >
		    <thead>
			<tr>
		    	<td></td>
		    	<td>下单时间</td>
		    	<td>订单编号</td>
		    </tr>
            </thead>
		</table>
			
			<button class="ordersubmit btn btn-default btn-lg">确 定</button>
		
		</div><!--orderWinpop-->
	
	</body>
	
</html> 




	
